
#pragma once
#include <queue>
#include <iostream>
#include <string>
#include "LockQueue.h"

enum LogLevel{
    DEBUG,
    INFO,
    ERROR,
    FATAL
};

class MrpcLog{
public:
    static MrpcLog & getInstance();//单例
    void SetLogLevel(LogLevel level);
    void log(std::string log); //写日志
private:
    LogLevel _log_level;
    LockQueue<std::string> _log_queue;
    //只有一个类
    MrpcLog();
    MrpcLog(const MrpcLog &&) = delete; //拷贝构造必须是引用，否则无线递归下去,禁止重载和覆盖以及重写。
    MrpcLog(const MrpcLog &) = delete; //const
};

//（logmsgformat, ...）表示格式化的参数列表
#define LOG_INFO(logmsgformat, ...)\
    do{ \
        MrpcLog &logger = MrpcLog::getInstance(); \
        logger.SetLogLevel(INFO); \
        char c[1024] = {0}; \
        snprintf(c, 1024, logmsgformat, ##__VA_ARGS__); \
        logger.log(c); \
    }while(0)

#define LOG_ERROR(logmsgformat, ...)\
    do{ \
        MrpcLog &logger = MrpcLog::getInstance(); \
        logger.SetLogLevel(ERROR); \
        char c[1024] = {0}; \
        snprintf(c, 1024, logmsgformat, ##__VA_ARGS__); \
        logger.log(c); \
    }while(0)
